#!/bin/bash
# It requires no paswd ssh

if [ ! $# -eq 4 ]
then
   echo "Usage: username nodes_file mosa_pack_file remote_dir"
   exit 1
fi

user=$1
nodes_file=$2
mosa_pack=$3
remote_dir=$4

{ while read NODE ; do

	echo "deploying mosa on $NODE"
	ssh -n $user@$NODE "if [ ! -f $remote_dir ] ; then mkdir -p $remote_dir ; fi"
	scp $mosa_pack *.sh $user@$NODE:/$remote_dir
	echo "unpacking and building"
	ssh -n $user@$NODE "cd $remote_dir ; unzip $mosa_pack ; bash build.sh mosa"
	scp *.sh $user@$NODE:/$remote_dir/mosa

done } < $nodes_file
